var core = require('core');
var wechat = core.wechat;

var sign = function(token, callback){

    core.api("open/upToken", {token: token, type: "TempToken", expires: Date.now()}, function(err, body){
        if(err || body.code)
            return callback(new core.send(200000));
        if(!body.docs)
            return callback(new core.send(300002));
        core.api("user/getUser", {openid: body.docs.data.oid, tagid_list: wechat.config.tagid_contrast[1]}, function(err, doc){
            if(err || doc.code)
                return callback(new core.send(100000));

            callback(body);
        });
    });

};

module.exports = sign;
